<?php
namespace app\common\logic;

use think\Controller;
class Trend extends Controller
{
    
    /**
     * 时时彩基本走势统计数据
     * @param 开奖数据 $array
     * @param 彩种id $game_id
     */
    public function getSscTrend($array=[],$game_id){
        $return = array();

        foreach ($array as &$value){
            $value['qihao'] = substr($value['qihao'], -4);
            	
            $v_1 = array($value['kjjg'][0],$value['kjjg'][1],$value['kjjg'][2]);
            $v_2 = array($value['kjjg'][3],$value['kjjg'][1],$value['kjjg'][2]);
            $v_3 = array($value['kjjg'][3],$value['kjjg'][4],$value['kjjg'][2]);
            $value['kjjg'] = kjjg_split($value['kjjg'], $game_id);
        
            $v_1 = array_unique($v_1);
        
            $v_2 = array_unique($v_2);
        
            $v_3 = array_unique($v_3);
            if(count($v_1)==2){
                $value['dat_type'][0] = '组三';
            }elseif(count($v_1==3)){
                $value['dat_type'][0] = '组六';
            }
            if(count($v_2)==2){
                $value['dat_type'][1] = '组三';
            }elseif(count($v_2==3)){
                $value['dat_type'][1] = '组六';
            }
            if(count($v_3)==2){
                $value['dat_type'][2] = '组三';
            }elseif(count($v_3==3)){
                $value['dat_type'][2] = '组六';
            }
        }
        $return['type'] = array('前三','中三','后三');
        $return['data'] = $array;
        return $return;
    }
    
    
    /**
     * PK10基本走势统计数据
     * @param 开奖数据 $array
     * @param 彩种id $game_id
     */
    public function getPk10Trend($array=[],$game_id){
        $return = array();
        foreach ($array as &$value){
            $value['kjjg'] = kjjg_split($value['kjjg'], $game_id);
            $value['dat_type'][] = $value['kjjg'][0] + $value['kjjg'][1];
            
        }
        $return['type'] = array('冠亚和');
        $return['data'] = $array;
        return $return;
    }
    
    
    /**
     * 快3基本走势统计数据
     * @param 开奖数据 $array
     * @param 彩种id $game_id
     */
    public function getK3Trend($array=[],$game_id){
        $return = array();
        foreach ($array as &$value){
            $value['kjjg'] = kjjg_split($value['kjjg'], $game_id);
            $value['dat_type'][0] = array_sum($value['kjjg']);
            $value['dat_type'][1] = max($value['kjjg']) - min($value['kjjg']);
            if(count(array_unique($value['kjjg'])) == 2){
                $value['dat_type'][2] = '二同号';
            }else if(count(array_unique($value['kjjg'])) == 1){
                $value['dat_type'][2] = '三同号';
            }else if(preg_match('/^(0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2}\d$/',implode($value['kjjg']))){
                $value['dat_type'][2] = '三连号';
            }else if(count($value['kjjg']) == count(array_unique($value['kjjg']))){
                $value['dat_type'][2] = '三不同号';
            }
            
        }
        $return['type'] = array('和值','跨度','形态');
        $return['data'] = $array;
        return $return;
    }
    
    
    /**
     * 11选5基本走势统计数据
     * @param 开奖数据 $array
     * @param 彩种id $game_id
     */
    public function get11x5Trend($array=[],$game_id){
        $return = array();
        foreach ($array as &$value){
            $value['kjjg'] = kjjg_split($value['kjjg'], $game_id);
            $value['dat_type'][0] = array_sum($value['kjjg']);
            $value['dat_type'][1] = $value['dat_type'][0] > 30 ? '大' : ($value['dat_type'][0] == 30 ? '和' : '小');
            $value['dat_type'][2] = $value['dat_type'][0] % 2 == 0 ? '双' : '单';
            $value['dat_type'][3] = $value['kjjg'][4] > $value['kjjg'][0] ? '龙' : '虎';
        }
        $return['type'] = array('3colspan'=>'总和','龙虎');
        $return['data'] = $array;
        return $return;
    }
    
    
    
    /**
     * 低频彩基本走势统计数据
     * @param 开奖数据 $array
     * @param 彩种id $game_id
     */
    public function getDpcTrend($array=[],$game_id){
        $return = array();
        foreach ($array as &$value){
            $value['qihao'] = substr($value['qihao'], -4);
            $value['kjjg'] = kjjg_split($value['kjjg'], $game_id);
            $value['dat_type'][0] = array_sum($value['kjjg']);
            $value['dat_type'][1] = max($value['kjjg']) - min($value['kjjg']);
            $v_1 = array($value['kjjg'][0],$value['kjjg'][1],$value['kjjg'][2]);
            $v_1 = array_unique($v_1);
            if(count($v_1)==2){
                $value['dat_type'][2] = '组三';
            }elseif(count($v_1==3)){
                $value['dat_type'][2] = '组六';
            }
        }
        $return['type'] = array('和值','跨度','形态');
        $return['data'] = $array;
        return $return;
    }
    
    
    
    /**
     * PC蛋蛋基本走势统计数据
     * @param 开奖数据 $array
     * @param 彩种id $game_id
     */
    public function getPcddTrend($array=[],$game_id){
        $return = array();
        foreach ($array as &$value){
            $value['qihao'] = substr($value['qihao'], -4);
            $value['kjjg'] = kjjg_split($value['kjjg'], $game_id);
            $big = $value['kjjg'][4] > 21 ? '极大' : ($value['kjjg'][4] < 6 ? '极小' : ($value['kjjg'][4] < 14 ? '小' : '大'));
            $odd = $value['kjjg'][4] % 2 == 0 ? '双' : '单';
            $value['dat_type'][0] = $big.$odd;
            $value['dat_type'][1] = bose($value['kjjg'][4]).'波';
            
        }
        $return['type'] = array('大小单双','色波');
        $return['data'] = $array;
        return $return;
    }
    
    
    
    /**
     * 六合彩基本走势统计数据
     * @param 开奖数据 $array
     * @param 彩种id $game_id
     */
    public function getHk6Trend($array=[],$game_id){
        $return = array();
        foreach ($array as &$value){
            $value['qihao'] = substr($value['qihao'], -4);
            $value['kjjg'] = kjjg_split($value['kjjg'], $game_id);
            $value['dat_type'][0] = array_sum($value['kjjg']);
            $value['dat_type'][1] = $value['dat_type'][0] % 2 == 0 ? '双' : '单';
            $value['dat_type'][2] = $value['dat_type'][0] > 174 ? '大' :  '小';
            $value['dat_type'][3] = Hk6bose($value['kjjg'][4]).'波';
        }
        $return['type'] = array('总数','单双','大小','七色波');
        $return['data'] = $array;
        return $return;
    }
    
    
    
    /**
     * 七星彩基本走势统计数据
     * @param 开奖数据 $array
     * @param 彩种id $game_id
     */
    public function getQxcTrend($array=[],$game_id){
        $return = array();
        foreach ($array as &$value){
            $value['qihao'] = substr($value['qihao'], -4);
            $value['kjjg'] = kjjg_split($value['kjjg'], $game_id);
            $value['dat_type'][0] = array_sum($value['kjjg']);
            $value['dat_type'][1] = $value['dat_type'][0] % 2 == 0 ? '双' : '单';
            $value['dat_type'][2] = $value['dat_type'][0] > 174 ? '大' :  '小';
            $value['dat_type'][3] = $value['dat_type'][0] % 10;
        }
        $return['type'] = array('总数','单双','大小','和尾');
        $return['data'] = $array;
        return $return;
    }
    
}